package com.vrv.common;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import com.vrv.netmgr.R;

public class SettingDialog implements OnClickListener{
	//
	private Dialog mDialog;
	private Button leftBtn,rightBtn;
	public EditText ipEdit;
	public EditText portEdit;
	//
	public SettingDialog(Context context){
		mDialog = new Dialog(context);
		mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		//
        Window window = mDialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        //
        layoutParams.width = 200;
        window.setAttributes(layoutParams);
        View layout = LayoutInflater.from(context).inflate(R.layout.view_setting_server, null);
        mDialog.show();
		//
		ipEdit = (EditText) layout.findViewById(R.id.ipEdit);
        portEdit = (EditText) layout.findViewById(R.id.portEdit);
		leftBtn=(Button) layout.findViewById(R.id.left_button);
		rightBtn=(Button) layout.findViewById(R.id.right_button);
		//为按钮设置事件监听
		leftBtn.setOnClickListener(this);
		rightBtn.setOnClickListener(this);
		mDialog.setContentView(layout);
	}
	//事件传递接口
		public interface MyDialogInt{
	        public void onClick(View view);
	    }

		MyDialogInt LeftcallBack = null;
		MyDialogInt RightcallBack = null;

		public void dismiss(){
			mDialog.dismiss();
		}

		public boolean isShowing(){
			return mDialog.isShowing();
		}
		public void onClick(View view) {
			if(view==leftBtn){
				LeftcallBack.onClick(view);
			}else if(view==rightBtn){
				RightcallBack.onClick(view);
			}
		}
		//设置左按钮
		public void setLeftButton(String value,MyDialogInt iBack){
			if(value==null||value.equals("")){
				return;
			}
			leftBtn.setVisibility(View.VISIBLE);
			leftBtn.setText(value);
			LeftcallBack=iBack;
		}

		//设置右按钮
		public void setRightButton(String value,MyDialogInt iBack){
			if(value==null||value.equals("")){
				return;
			}
			rightBtn.setVisibility(View.VISIBLE);
			rightBtn.setText(value);
			RightcallBack=iBack;
		}
		//控件设置和获取ip的方法
		public String getIp(){
			return ipEdit.getText().toString().trim();
		}
		public void setIp(String string){
			ipEdit.setText(string);
		}
		//控件设置和获取port的方法
		public String getPort(){
			return portEdit.getText().toString().trim();
		}
		public void setPort(String string){
			portEdit.setText(string);
		}
}
